package com.mailbox.mailbox.util.SendEmail;

import cn.hutool.extra.mail.Mail;
import cn.hutool.extra.mail.MailAccount;


/**
 * @author 张铭辉
 */
public class SendEmailUtil {
    public static void sendEmail(String emailCode, String tos, String flag) {
        // 封装
        MailAccount account = new MailAccount();
        // 设置用户
        account.setUser("官方验证码");
        if(flag.equals("@163.com")){
            account.setUser("zhang1431835456@163.com");
            account.setHost("smtp.163.com");
            account.setPass("NYGEIFJRGDZZDZJW");
            account.setFrom("校长信箱<zhang1431835456@163.com>");
        }else if(flag.equals("@qq.com")){
            account.setUser("1431835456@qq.com");
            account.setHost("smtp.qq.com");
            account.setPass("tozrrucwejgrfhcj");
            account.setFrom("校长信箱<1431835456@qq.com>");
        }
        account.setPort(465);
        account.setAuth(true);

        // ssl方式发送
        account.setSslEnable(true);
        // 使用STARTTLS安全连接
        account.setStarttlsEnable(true);
        // 发送
        try {
            Mail.create(account)
                    .setTos(tos)
                    .setTitle("验证码邮件")
                    .setContent("尊敬的用户,您好:\n"
                            + "\n本次请求的邮件验证码为:" + emailCode+",本验证码 5 分钟内效，请及时输入。（请勿泄露此验证码）\n"
                            + "\n如非本人操作，请忽略该邮件。\n(这是一封通过自动发送的邮件，请不要直接回复）"+
                            "<a href = 'www.baidu.com'>百度</a>")
                    .setHtml(true)
                    //关闭session
                    .setUseGlobalSession(false)
                    .send();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
